//
//	 ______    ______    ______
//	/\  __ \  /\  ___\  /\  ___\
//	\ \  __<  \ \  __\_ \ \  __\_
//	 \ \_____\ \ \_____\ \ \_____\
//	  \/_____/  \/_____/  \/_____/
//
//	Powered by BeeFramework
//
//
//  ForgetPassWord2.m
//  dingding
//
//  Created by LHL on 14/12/15.
//  Copyright (c) 2014年 com.gordon. All rights reserved.
//

#import "ForgetPassWordFinal.h"
#import "Board_iPhone_Login2.h"
#pragma mark -

@interface ForgetPassWordFinal()
{
    //<#@private var#>
}
@end

@implementation ForgetPassWordFinal

SUPPORT_AUTOMATIC_LAYOUT( YES )
SUPPORT_RESOURCE_LOADING( YES )
DEF_OUTLET(BeeUITextField, newpwd)
DEF_OUTLET(BeeUITextField, reviewPwd)
DEF_OUTLET(BeeUIButton, confirmbutton)
DEF_MODEL(forgotPassword, iforgotPassword)
- (void)load
{
    self.iforgotPassword = [forgotPassword modelWithObserver:self];
}

- (void)unload
{
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
    return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return [gestureRecognizer isKindOfClass:UIScreenEdgePanGestureRecognizer.class];
}


#pragma mark - Signal

ON_CREATE_VIEWS( signal )
{
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    self.navigationBarShown = YES;
    self.title = @"找回密码";
    self.navigationBarLeft = [UIImage imageNamed:@"back.png"];
}

-(void)popFunc{
    for (UIViewController *vc in self.navigationController.viewControllers) {
        if ([vc isKindOfClass:[Board_iPhone_Login2 class]]) {
            [self.navigationController popToViewController:vc animated:YES];
        }
    }
}

ON_SIGNAL3(forgotPassword, RELOADED, SIGNAL){
    [self dismissTips];
    if ([self.iforgotPassword.code isEqualToString:@"200"]) {
        [self presentMessageTips:@"修改成功"];
        [self performSelector:@selector(popFunc) withObject:nil afterDelay:1.0];
    }else{
        [self presentMessageTips:self.iforgotPassword.msg];
    }
}

ON_SIGNAL3(forgotPassword, RELOADING, SIGNAL){
    [self presentLoadingTips:@"加载中"];
}

ON_SIGNAL3(forgotPassword, FAILED, SIGNAL){
    [self dismissTips];
    [self presentMessageTips:self.iforgotPassword.msg];
}

ON_SIGNAL3(BeeUIButton, confirmbutton, SIGNAL){
    if (self.newpwd.text.length < 6) {
        [self presentMessageTips:@"新密码长度不能小于6位"];
        return;
    }
    if (self.reviewPwd.text. length <6) {
        [self presentMessageTips:@"重复密码长度不能小于6位"];
        return;
    }
    if (![self.reviewPwd.text isEqualToString:self.newpwd.text]) {
        [self presentMessageTips:@"新密码与重复密码不一致"];
        return;
    }
    self.iforgotPassword.phone = self.phone;
    self.iforgotPassword.newpassword = self.newpwd.text;
    [self.iforgotPassword firstPage];
}


ON_DELETE_VIEWS( signal )
{
}

ON_LAYOUT_VIEWS( signal )
{
}

ON_WILL_APPEAR( signal )
{
}

ON_DID_APPEAR( signal )
{
}

ON_WILL_DISAPPEAR( signal )
{
}

ON_DID_DISAPPEAR( signal )
{
}

ON_SIGNAL3( BeeUINavigationBar, LEFT_TOUCHED, signal )
{
    [self.navigationController popViewControllerAnimated:YES];
}

ON_SIGNAL3( BeeUINavigationBar, RIGHT_TOUCHED, signal )
{
    
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self resign];
}

-(void)resign{
    for (UIView *t in self.view.subviews) {
        if ([t isKindOfClass:[BeeUITextField class]]) {
            [t resignFirstResponder];
        }
    }
}

@end
